﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;

namespace ElasticA.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class ConsumerController : ControllerBase
    {
        private readonly IHttpClientFactory _httpClientFactory;

        public ConsumerController(IHttpClientFactory httpClientFactory)
        {
            _httpClientFactory = httpClientFactory;
        }

        private const string BaseUri = "http://localhost:8220";

        [HttpGet("a")]
        public async Task<string> A()
        { 
            var client = _httpClientFactory.CreateClient();
            Thread.Sleep(new Random().Next(1, 1500));

            var b = await client.GetStringAsync($"{BaseUri}/api/DataSource/b");

            var c = await client.GetStringAsync($"{BaseUri}/api/DataSource/c");

            var d = await client.GetStringAsync($"{BaseUri}/api/DataSource/d");

            var e = await client.GetStringAsync($"{BaseUri}/api/DataSource/e");

            return $"b={b} & c={c} & d={d} & e={e}";
        }
    }
}